from flask import Flask, request, jsonify

import pdfToPic
import picMergePdf

app = Flask(__name__)

# 存储数据的简单内存数据库
data_store = []


@app.route('/', methods=['GET'])
def home():
    """首页路由"""
    return jsonify({
        "message": "欢迎使用Python HTTP服务器",
        "endpoints": {
            "GET /": "首页",
            "POST /pdfToPic": "pdf转图片,参数：path=pdf路径",
            "POST /picMergePdf": "图片合并成pdf,参数：sourcePath=文件或文件夹路径或文件名数组&targetPath=目标路径&name=合并名称",
        }
    })


@app.route('/pdfToPic', methods=['POST'])
def pdf_pic():
    received_data = request.get_json()
    pdfToPic.pdf_pic_path(received_data['path'])
    return jsonify({"status": "success", "code": 200})


@app.route('/picMergePdf', methods=['POST'])
def merge():
    received_data = request.get_json()
    sourcePath = received_data["sourcePath"]
    targetPath = received_data["targetPath"]
    name = received_data["name"]
    picMergePdf.merge_path(sourcePath, targetPath, name)
    return jsonify({"status": "success", "code": 200})


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
